<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        名字：<input type="text" id="text">
    </div>
    <div>
        建议： <span id="advice"></span>

    </div>

</body>

</html>
<script>
    let text = document.getElementById("text");
    let advice = document.getElementById("advice");
    text.onkeydown = function() {
        if (this.value === "") {
            return;
        }
        // 实例化XMLHttpRequest对象
        let http = new XMLHttpRequest();
        // 规划一个HTTP请求
        http.open("get", "http://10.35.164.168/name.php?name=" + this.value);
        // 发送对象
        http.send();
        //接受来自服务器的请求 
        http.onreadystatechange = function() {
            if (http.readyState === 4) {
                advice.innerHTML = http.responseText;
                console.log(http.responseText);
            }
        }
    }
</script>